#include <filesystem>
#include <iostream>
#include <string>
#include <regex>
#include <vector>
#include <string_view>

namespace fs = std::filesystem;

namespace impl
{
std::vector<fs::directory_entry> find_files(fs::path const& path,
                                            std::string_view pattern)
{
    std::vector<fs::directory_entry> result;
    std::regex rx(pattern.data());
    std::copy_if(fs::recursive_directory_iterator(path),
                 fs::recursive_directory_iterator(),
                 std::back_inserter(result),
                 [&rx](fs::directory_entry const& ent) {
                     return fs::is_regular_file(ent.path()) &&
                            std::regex_match(ent.path().filename().string(),
                                             rx);
                 });

    return result;
}
}  // namespace impl

using namespace std;
int main(int argc, char** argv)
{
    fs::path dir = "../";
    auto pattern = R"(find_files\.cpp)";
    auto result = impl::find_files(dir, pattern);
    copy(result.begin(),
         result.end(),
         std::ostream_iterator<fs::directory_entry>(cout, "\n"));
    return 0;
}